<template>
	<view class="custom_forward_button">
		<view class="share_button" v-if="!isShare" @click="shareHandle">转发给他（她）</view>
		<view class="share_button" :class="isShare && 'on'" v-else>已转发</view>
	</view>
</template>

<script>
	export default {
		name:"custom-forward-button",
		props:{
			item:{
				type:Object,
				default(){
					return {}
				}
			}
		},
		data() {
			return {
				isShare:false
			};
		},
		methods:{
			shareHandle(){
				let that = this;
				return new Promise((resolve, reject) => {
					that.$store
						.dispatch('shareTo', {
							userId:that.$props.item.userId,
							newsId:that.$props.item.newsId
						})
						.then(res => {
							that.isShare = true
							resolve();
						})
						.catch(err => {
							console.log(err);
							reject(err);
						});
				});
			}
		}
	}
</script>

<style lang="less">
.custom_forward_button{
	.share_button{
		font-size: 24rpx;
		padding:12rpx 20rpx;
		border:2rpx #CCCCCC solid;
		border-radius: 10rpx;
		color:#333333;
		&.on{
			color:#CCCCCC;
		}
	}
}
</style>
